package org.wenhua.yuan.demo_test;

public class DemoTest {

    private static DemoTest test1;
    private static DemoTest test2;
    public static void main(String[] args) {

        test2 = new DemoTest();
        test1 = new DemoTest();


        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                test1.lprint4("thread1");
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                test1.lprint3("thread2");
            }
        });
        thread1.start();
        thread2.start();
    }


    private void lprint (String id) {
        System.out.println("lprint打印前期 - ："+id);
        synchronized (test1) {
            for (int i = 0; i < 20; i++) {
                System.out.println(i+"序号，lprint打印后期："+id);
            }
        }

    }

    private void lprint2 (String id) {
        System.out.println("lprint2打印前期 - ："+id);
        synchronized (test2) {
            for (int i = 0; i < 20; i++) {
                System.out.println(i+"序号，lprint2打印后期："+id);
            }
        }

    }

    private synchronized void lprint3 (String id) {
        System.out.println("lprint3打印前期 - ："+id);
            for (int i = 0; i < 20; i++) {
                System.out.println(i+"序号，lprint3打印后期："+id);
            }

    }

    private  void lprint4 (String id) {
        System.out.println("lprint4打印前期 - ："+id);
            for (int i = 0; i < 20; i++) {
                System.out.println(i+"序号，lprint4打印后期："+id);
            }

    }

}
